layui.define(['table', 'form'], function(exports){
  var $ = layui.$,table = layui.table,form = layui.form;

  table.render({
    elem: '#LAY-table'
    ,url: layui.setter.webRoot + '/cdb/order/working/list.data'
    ,method: 'post'
    ,parseData: function (res) {
        return {
            "code": res.code,
            "msg": res.msg,
            "count": res.body.total,
            "data": res.body.data
        };
    }
    ,response: {statusCode: 200}
    ,cols: [[
      {field: 'tradeNo', title: '订单号'}
      ,{field: 'leaseChargingCabinetSn', title: '租借设备',templet:function (record){
              if(record.leaseChargingCabinetSn) {
                  return record.leaseChargingCabinetSn + '(卡槽：' + record.leaseSlotNum + ')';
              }else{
                  return '--';
              }
          }}
      ,{field: 'revertChargingCabinetSn', title: '归还设备',templet:function (record){
              if(record.revertChargingCabinetSn) {
                  return record.revertChargingCabinetSn + '(卡槽：' + record.revertSlotNum + ')';
              }else{
                  return '--';
              }
          }}
      ,{field: 'portableBatterySn', title: '充电宝ID'}
      ,{field: 'useDurationStr', title: '使用时长'}
      ,{field: 'depositMoneyStr', title: '押金'}
      ,{field: 'payStateName', title: '支付状态'}
      ,{field: 'stateName', title: '状态'}
      ,{field: 'createDate', title: '创建时间'}
      ,{title: '操作', width: 90, align:'center', fixed: 'right', toolbar: '#LAY-table-toolbar'}
    ]]
    ,page: false
    ,height: 'full-220'
    ,text: '对不起，加载出现异常！'
  });
  
  //监听搜索
  form.on('submit(LAY-search)', function(data){
    var field = data.field;
    //执行重载
    table.reload('LAY-table', {
      where: field
    });
  });
  
  //事件
  var active = {
      del:function(obj){
        layer.confirm('确定要删除该缓存信息吗？', function(index){
            $.ajax({
                type: "post",
                url: layui.setter.webRoot + '/cdb/order/working/del.do',
                data:{tradeNo:obj.data.tradeNo},
                dataType:"json",
                success:function(res){
                    if(res.code == 200){
                        obj.del();
                    }else{
                        layer.msg(res.msg,{icon: 5});
                    }
                }
            });
            layer.close(index);
        });
    }
  };
  
  $('.layui-btn.LAY-btn-fun').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
  
  table.on('tool(LAY-table)', function(obj){
  	var type = obj.event ;
   	active[type] ? active[type].call(this,obj) : '';
  });
  
  exports('battery_cabinet_order_working_list', {})
});